﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Seesmic.Sdp.Extensibility;
using System.Collections.Generic;
using Seesmic.Sdp.Utils;
using System.Collections.ObjectModel;

namespace Seesmic.HelloTipi
{
    public class HelloTipiSideBarAction : TimelineSidebarAction, ISidebarAction, ISidebarActionGroup
    {

        private ObservableCollection<ISidebarAction> _TimelineSidebarItems;
        private HelloTipiAccount _account;

        private DataTemplate _icon = null;
       
        public HelloTipiSideBarAction(HelloTipiAccount account, HelloTipiFriendsTimeLineItemsProvider itemProvider)
        {
           this._account = account;           
           this.Title = account.ScreenName;

           this._TimelineSidebarItems = new ObservableCollection<ISidebarAction>();

           this.Timeline = itemProvider.Timeline;

           _icon = HelloTipiPlugin.AccountIcon;
        }

        public HelloTipiSideBarAction(HelloTipiAccount account, HelloTipiFamilyTimeLineItemsProvider itemProvider)
        {
            this._account = account;
            this.Title = account.ScreenName;

            this._TimelineSidebarItems = new ObservableCollection<ISidebarAction>();

            this.Timeline = itemProvider.Timeline;
        }

        public HelloTipiSideBarAction(HelloTipiAccount account, HelloTipiUserTimeLineItemsProvider itemProvider)
        {
            this._account = account;
            this.Title = account.ScreenName;

            this._TimelineSidebarItems = new ObservableCollection<ISidebarAction>();

            this.Timeline = itemProvider.Timeline;
        }

        public HelloTipiSideBarAction(HelloTipiAccount account, HelloTipiDirectMessagesTimeLineItemsProvider itemProvider)
        {
            this._account = account;
            this.Title = account.ScreenName;

            this._TimelineSidebarItems = new ObservableCollection<ISidebarAction>();

            this.Timeline = itemProvider.Timeline;
        }
        

        internal bool AddTimelineSidebarItem(ISidebarAction sidebarItem)
        {
            if (!this._TimelineSidebarItems.Contains(sidebarItem))
            {
                this._TimelineSidebarItems.Add(sidebarItem);
                return true;
            }
            return false;
        }

        #region ISidebarAction Members

        public HelloTipiAccount Account
        {
            get
            {
                return this._account;
            }
        }

        public override DataTemplate Icon
        {
            get
            {
                return _icon;
            }
        }

        public override string PersistId
        {
            get
            {                
                return string.Format("{0}_{1}", this.Account.Username, base.PersistId);
            }
        }

        /*public override string Text
        {
            get
            {
                return this.Account.Username;
            }
        }*/
               
        #endregion

        #region ISidebarActionGroup Members

        public bool CanInvoke
        {
            get
            {
                return true;
            }
        }

        public IList<ISidebarAction> SidebarActions
        {
            get
            {
                return this._TimelineSidebarItems;
            }
        }

        #endregion
    }
}
